package com.zzty.springmybatis.DAO;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zzty.springmybatis.entity.SelfExam;
import com.zzty.springmybatis.entity.TeamExam;

public interface TeamExamDAO {
	
	@Insert("insert into teamexam (id,date,questions,clazzId) values (#{id},#{date},#{questions},#{clazzId})")
	public void addTeamExam(TeamExam te);
	
	@Update("update teamexam set winnerId1=#{winnerId1} , winnerId2=#{winnerId2} where id=#{id}")
	public void updateWinnerIds(TeamExam teamExam);
	
	@Select("select * from teamexam where date=#{date} and clazzId=#{clazzId}")
	public TeamExam getInfoByDateAndClazzId(@Param("date") String date,@Param("clazzId") Integer clazzId);
	
	@Select("#{sql}")
	public List<TeamExam> selectBySql(String sql);
	
	@Select("select max(id) from teamexam")
	public Integer getNextId();
	
	@Select("select * from teamexam where clazzId=#{clazzId} order by date desc limit #{page},5")
	public List<TeamExam> searchTeamExamByClazzId(@Param("clazzId") Integer clazzId, @Param("page") Integer page);

	@Select("select * from teamexam where clazzId=#{clazzId}")
	public List<TeamExam> searchTeamExamOnlyByClazzId(@Param("clazzId") Integer clazzId);
	
	@Insert("INSERT INTO teamexam (date,questions,clazzId) VALUES (#{date},#{questions},#{clazzId});SELECT @@Identity")
	public Integer searchNewId(@Param("date") String date, @Param("questions") String questions,
			@Param("clazzId") Integer clazzId);
	
	@Select("select *  from selfexam where clazzId=#{clazzId} and winnerId is null")
	public List<TeamExam> searchTeamExamByWinnerIdAndClazzId(@Param("clazzId") Integer clazzId);
	
	@Select("select * from teamexam where clazzId=#{clazzId} order by date  limit #{page},10")
	public List<TeamExam> searchTenTeamExamByClazzId(@Param("clazzId") Integer clazzId, @Param("page") Integer page);
	
}
